package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.Platform;
import com.briup.jz.bean.PlatformExample;
import com.briup.jz.dao.PlatformMapper;
import com.briup.jz.service.IPlatformService;
import com.briup.jz.utils.CustomerException;

@Service
public class PlatformImpl implements IPlatformService{
	@Autowired
	private PlatformMapper platformMapper;

	@Override
	public List<Platform> query(Double balance, String bank_card) {
		// TODO Auto-generated method stub
		PlatformExample example = new PlatformExample();
		PlatformExample.Criteria criteria = example.createCriteria();
    	
    	if(balance !=null) {
			criteria.andBalanceEqualTo(balance);			
		}
		if(bank_card !=null) {
			criteria.andBankCardEqualTo(bank_card);
		}
    	
    	return platformMapper.selectByExample(example);
	}

	@Override
	public void saveOrUpdate(Platform platform) throws Exception {
		// TODO Auto-generated method stub
		if(platform.getId()!=null) {
			platformMapper.updateByPrimaryKey(platform);
		}else {
			platformMapper.insert(platform);
		}
		
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		// TODO Auto-generated method stub
		Platform platform = platformMapper.selectByPrimaryKey(id);
		if (platform == null) {
			throw new CustomerException("要删除的信息不存在");
		} else {
			platformMapper.deleteByPrimaryKey(id);
		}
	} 
	
}
